package com.link2room.bumblebee.controller.api;


import com.link2room.bumblebee.constant.SysOptionConstant;
import com.link2room.bumblebee.facade.ISysOptionFacadeService;
import com.link2room.common.dto.param.base.SysOptionBaseParamDto;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.dto.result.base.SysOptionDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.link2room.bumblebee.constant.SysOptionConstant.Category.SERVICE_DOMAIN;
import static com.link2room.bumblebee.constant.SysOptionConstant.Category.WXAPPID_DOMAIN_MAPPING;


/**
 * 获取sysOptions
 * Created by Ln on 2016/12/20.
 */
@Api(tags = "获取sysOptions")
@RestController
@RequestMapping("/api")
public class SysOptionApiController {
    @Resource
    private ISysOptionFacadeService sysOptionFacadeService;


    @ApiOperation(value = "服务域名获取", response = SysOptionDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "item",value = "item", paramType = "query", required = true),
    })
    @RequestMapping(value = "/ServiceDomains",method= RequestMethod.GET)
    public @ResponseBody
    BaseResultDto serviceDomain(
            @RequestParam(value = "item" ,required = true) String item
    ) throws Exception {
        SysOptionBaseParamDto paramDto = new SysOptionBaseParamDto();
        paramDto.setItem(item);
        paramDto.setCategory(SERVICE_DOMAIN);
        SysOptionDto res = sysOptionFacadeService.findSysOption(paramDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(res);
        return l2rRs;
    }

    @ApiOperation(value = "服务域名映射集团代码", response = SysOptionDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "item",value = "域名", paramType = "query", required = true),
    })
    @RequestMapping(value = "/lhotelGroupCode",method= RequestMethod.GET)
    public @ResponseBody
    BaseResultDto lhotelGroupCode(
            @RequestParam(value = "item" ,required = true) String item
    ) throws Exception {
        SysOptionBaseParamDto paramDto = new SysOptionBaseParamDto();
        paramDto.setItem(item);
        paramDto.setCategory(SysOptionConstant.Category.LHOTEL_GROUP_CODE);
        paramDto.setLhotelGroupCode(null);
        SysOptionDto res = sysOptionFacadeService.findSysOption(paramDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(res);
        return l2rRs;
    }

    @ApiOperation(value = "服务域名映射微信公众号appid", response = SysOptionDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "item",value = "域名", paramType = "query", required = true),
    })
    @RequestMapping(value = "/wxAppids",method= RequestMethod.GET)
    public @ResponseBody
    BaseResultDto wxAppids(
            @RequestParam(value = "item" ,required = false) String item
    ) throws Exception {
        SysOptionBaseParamDto paramDto = new SysOptionBaseParamDto();
        paramDto.setItem(item);
        paramDto.setCategory(WXAPPID_DOMAIN_MAPPING);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(sysOptionFacadeService.findSysOptions(paramDto));
        return l2rRs;
    }

}
